﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace RFIDStockManagement.Client.IOStock
{
    public partial class EditStockPlace : BaseForm
    {
        public long StockPlaceId { get; set; }
        public string StockPlaceName { get; set; }

        private DataTable m_StockPlace = null;
        private string m_ItemName = string.Empty;
        private string m_UnitName = string.Empty;
        private string m_StockName = string.Empty;
        public EditStockPlace(string itemName, string unitName, string stockName, DataTable stockPlace)
        {
            InitializeComponent();
            m_ItemName = itemName;
            m_UnitName = unitName;
            m_StockName = stockName;
            m_StockPlace = stockPlace;

        }

        private void btnCancle_Click(object sender, EventArgs e)
        {

            this.Close();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (cbbStockPlace.SelectedIndex < 0)
            {
                AlertForm.ShowMessage("仓位不能为空");
                return;
            }

            StockPlaceId = m_StockPlaceIndex[cbbStockPlace.SelectedIndex];
            StockPlaceName = cbbStockPlace.SelectedItem.ToString();
            this.Close();
        }

        private Dictionary<int, long> m_StockPlaceIndex = new Dictionary<int, long>();
        private void EditStockPlace_Load(object sender, EventArgs e)
        {
            if (m_StockPlace != null)
            {
                cbbStockPlace.Properties.BeginUpdate();
                foreach (DataRow row in m_StockPlace.Rows)
                {
                    int index = cbbStockPlace.Properties.Items.Add(row["FName"]);
                    long id = long.Parse(row["FID"].ToString());
                    m_StockPlaceIndex[index] = id;
                }
                cbbStockPlace.Properties.EndUpdate();

                txtItemName.Text = m_ItemName;
                txtUnitName.Text = m_UnitName;
                txtStockName.Text = m_StockName;
            }
        }
    }
}